import { useState } from 'react';
import { TableFilters } from './types';

// 通用的表格筛选hook
export function useTableFilters(initialFilters: Partial<TableFilters> = {}) {
  const [filters, setFilters] = useState<TableFilters>({
    searchTerm: '',
    statusFilter: 'all',
    typeFilter: 'all',
    categoryFilter: 'all',
    ...initialFilters,
  });

  const updateFilter = (key: keyof TableFilters, value: string) => {
    setFilters(prev => ({ ...prev, [key]: value }));
  };

  const resetFilters = () => {
    setFilters({
      searchTerm: '',
      statusFilter: 'all',
      typeFilter: 'all',
      categoryFilter: 'all',
      ...initialFilters,
    });
  };

  return {
    filters,
    updateFilter,
    resetFilters,
    setSearchTerm: (value: string) => updateFilter('searchTerm', value),
    setStatusFilter: (value: string) => updateFilter('statusFilter', value),
    setTypeFilter: (value: string) => updateFilter('typeFilter', value),
    setCategoryFilter: (value: string) => updateFilter('categoryFilter', value),
  };
} 